package cn.wolfcode.crm.Service.impl;


import cn.wolfcode.crm.Service.IRoleService;
import cn.wolfcode.crm.domain.Permission;
import cn.wolfcode.crm.domain.Role;
import cn.wolfcode.crm.mapper.RoleMapper;
import cn.wolfcode.crm.query.RoleQuery;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements IRoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        int i = roleMapper.deleteByPrimaryKey(id);
        return i;
    }

    @Override
    public int insert(Role record) {
        int i = roleMapper.insert(record);
        return  i;
    }

    @Override
    public Role selectByPrimaryKey(Long id) {
        Role role = roleMapper.selectByPrimaryKey(id);
        return role;
    }

    @Override
    public Role selectOne(Long id) {
        Role role = roleMapper.selectOne(id);
        return role;
    }

    @Override
    public List<Role> selectAll() {
        List<Role> roleList = roleMapper.selectAll();
        return roleList;
    }

    @Override
    public int updateByPrimaryKey(Role record) {
        int i = roleMapper.updateByPrimaryKey(record);
        return i;
    }



    @Override
    public PageInfo<Role> queryForList(RoleQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Role> list = roleMapper.queryForList(qo);
        return new PageInfo<>(list);

    }

    @Override
    public void insertRelation(Long roleId, Long permissionId) {
        roleMapper.insertRelation(roleId,permissionId);
    }

    @Override
    public List<Permission> getPresentPermission(Long id) {
        return roleMapper.getPresentPermission(id);
    }

    @Override
    public void deleteRelation(Long id) {
        roleMapper.deleteRelation(id);
    }

    @Override
    public void insertPersonRelation(Long employee_id, Long role_id) {
        roleMapper.insertPersonRelation(employee_id,role_id);
    }

    @Override
    public void deletePersonRelation(Long id) {
        roleMapper.deletePersonRelation(id);
    }
}
